package com.google.code.ptrends.common;

import static org.quartz.CronScheduleBuilder.cronSchedule;
import static org.quartz.DateBuilder.evenMinuteDate;
import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;

import java.util.Calendar;
import java.util.Date;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.Trigger;
import org.quartz.impl.StdSchedulerFactory;

public class ETLBootstrapper {
	public void run() throws SchedulerException {

		final SchedulerFactory factory = new StdSchedulerFactory();
		final Scheduler sched = factory.getScheduler();

		final JobDetail job = newJob(RetJob.class).withIdentity("job1", "group1")
				.build();

		final Date runTime = evenMinuteDate(Calendar.getInstance().getTime());
		
		final Trigger trigger = newTrigger().withIdentity("trigger1", "group1")
		.withSchedule(cronSchedule("0 0/3 * * * ?"))
		.startAt(runTime).build();
		sched.scheduleJob(job, trigger);

		sched.start();
	}
}
